package com.shj.em.biz.company.controller;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;
import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.shj.em.common.annotation.Log;
import com.shj.em.base.support.ResMsg;
import com.shj.em.base.vo.PageVO;

import com.shj.em.biz.company.entity.Contact;
import com.shj.em.biz.company.service.ContactService;
import com.baomidou.mybatisplus.plugins.Page;
import lombok.extern.slf4j.Slf4j;
import com.shj.em.base.controller.BaseController;


/**
 * <p>
 * 联系人信息 前端控制器
 * </p>
 *
 * @author Shen Huang Jian
 * @since 2018-07-07
 */
@RestController
@Slf4j
@RequestMapping("/contact")
public class ContactController extends BaseController<Contact>{

    @RequestMapping("/findByCompanyId/{companyId}")
    @ResponseBody
    public ResMsg<List<Contact>> findContactsByCompanyId(@PathVariable Long companyId){
        List<Contact> list = contactService.findContactsByCompanyId(companyId);
        return ResMsg.ok(list);
    }


    @Log("创建联系人信息")
    @PostMapping
    public ResMsg add(@RequestBody Contact contact){
        contactService.insert(contact);
        return ResMsg.ok(new Contact());
    }

    @Log("更新联系人信息")
    @PutMapping
    public ResMsg edit(@RequestBody Contact contact){
        contactService.updateById(contact);
        return ResMsg.ok();
    }

    @Log("批量删除联系人信息")
    @DeleteMapping( "/batchRemove/{ids}")
    public ResMsg batchRemove(@PathVariable("ids") String ids){
        contactService.deleteBatchIds(Arrays.asList(ids.split(",")));
        return ResMsg.ok();
    }

}

